﻿

using Furion.DependencyInjection;
using Furion.DynamicApiController;
using Furion.FriendlyException;
using Furion.TaskQueue;
using Furion.TimeCrontab;
using IotClientService.Consts;
using IotClientService.Models.RealData;
using IotClientWeb.Models.HK;
using IotContract.Enums;
using IotContract.Interfaces.Db;
using IotContract.Interfaces.Http;
using IotContract.Models.InfluxDb;
using Mapster;
using Microsoft.AspNetCore.Mvc;
using XT.Common.Extensions;
using XT.Common.Services;

namespace IotClientWeb.Controllers;

/// <summary>
/// 第三方设备API对接服务，充放电柜、OCV、注液等设备
/// </summary>
[ApiDescriptionSettings(IotApiConst.HK)]
[Route("fms/restful/api/v3/")]
[NonUnify]
public class HkService:IDynamicApiController, ITransient
{
    private readonly IClientWebService _webService;
    public HkService(IClientWebService clientWebService)
    {
        _webService=clientWebService;
    }
    /// <summary>
    /// 系统向FMS查询指定库位中的托盘信息
    /// </summary>
    /// <param name="request"></param>
    /// <returns></returns>
    [HttpPost]
    [Route("inventory/getTrayInfoByLocation")]
    public async Task<LocationTrayResponse> GetTrayInfoByLocation(LocationTrayRequest request)
    {
        _webService.InvokeValueChangeEvent("GetTrayInfoByLocation");
        return new LocationTrayResponse();
    }
    /// <summary>
    /// 电源柜系统向FMS上报库位状态
    /// </summary>
    /// <param name="request"></param>
    /// <returns></returns>
    [HttpPost]
    [Route("inventory/postDeviceStatusByLocation")]
    public async Task<HkResponse> PostDeviceStatusByLocation(DeviceStatusRequest request)
    {
        _webService.InvokeValueChangeEvent("PostDeviceStatusByLocation");
        return new HkResponse();
    }
    /// <summary>
    /// 当化成库位等点位设备向FMS上报生产数据
    /// </summary>
    /// <param name="request"></param>
    /// <returns></returns>
    [HttpPost]
    [Route("process/processDataByLocation")]
    public async Task<HkResponse> ProcessDataByLocation(ProcessLocationDataRequest request)
    {
        _webService.InvokeValueChangeEvent("ProcessDataByLocation");
        return new HkResponse();
    }
    /// <summary>
    /// 用于电源柜等点位设备向FMS上报工序结束
    /// </summary>
    /// <param name="request"></param>
    /// <returns></returns>
    [HttpPost]
    [Route("process/processCompleteByLocation")]
    public async Task<HkResponse> ProcessCompleteByLocation(LocationCompleteRequest request)
    {
        _webService.InvokeValueChangeEvent("ProcessCompleteByLocation");
        return new HkResponse();    
    }
    /// <summary>
    /// 化成、分容柜需要通过堆垛机将托盘取出库位时，调用此接口
    /// </summary>
    /// <param name="request"></param>
    /// <returns></returns>
    [HttpPost]
    [Route("process/noticeTakeOut")]
    public async Task<HkResponse> NoticeTakeOut(NoticeTakeOutRequest request)
    {
        _webService.InvokeValueChangeEvent("NoticeTakeOut");
        return new HkResponse();
    }
    /// <summary>
    /// 当库位发生火灾时，系统调用该接口，通知火警
    /// </summary>
    /// <param name="request"></param>
    /// <returns></returns>
    [HttpPost]
    [Route("fireAlarm/fireAlarmByLocation")]
    public async Task<HkResponse> FireAlarm(FireAlarmRequest request)
    {
        _webService.InvokeValueChangeEvent("fireAlarmByLocation");
        _webService.InvokeWarnEvent(new IotContract.Dtos.Clients.IotEquipWarnDto
        {
            EquipNum = request.HouseCode,
            EquipType = IotEquipType.FMT.ToString(),
            ErrorCode = "999",
            ProtobufType=IotProtobufType.WEB_API.ToString()          
        });
        return new HkResponse();
    }
    /// <summary>
    /// 组盘信息查询  在进行OCV/DCIR等工序时,获取托盘中的物料信息
    /// </summary>
    /// <param name="request"></param>
    /// <returns></returns>
    [HttpPost]
    [Route("material/queryAssembleInfo")]
    public async Task<AssembleInfosResponse> QueryAssembleInfo(QueryAssembleRequest request)
    {
        _webService.InvokeValueChangeEvent("QueryAssembleInfo");
        return new AssembleInfosResponse();
    }

    /// <summary>
    /// 设备向FMS上报生产数据
    /// </summary>
    /// <param name="request"></param>
    /// <returns></returns>
    [HttpPost]
    [Route("process/processDataByDevice")]
    public async Task<HkResponse> ProcessDataByDevice(ProcessDeviceDataRequest request)
    {
        _webService.InvokeValueChangeEvent("ProcessDataByDevice");
        return new HkResponse();
    }

    /// <summary>
    /// 用于电源柜等点位设备向FMS上报工序结束
    /// </summary>
    /// <param name="request"></param>
    /// <returns></returns>
    [HttpPost]
    [Route("process/processCompleteByDevice")]
    public async Task<HkResponse> ProcessCompleteByDevice(DeviceCompleteRequest request)
    {
        _webService.InvokeValueChangeEvent("ProcessCompleteByDevice");
        return new HkResponse();
    }
    /// <summary>
    /// 组盘数据上报（整盘上报）,用于注液系统
    /// </summary>
    /// <param name="request"></param>
    /// <returns></returns>
    [HttpPost]
    [Route("material/postAssembleInfo")]
    public async Task<HkResponse> PostAssembleInfo(ReportAssembleRequest request)
    {
        _webService.InvokeValueChangeEvent("PostAssembleInfo");
        return new HkResponse();
    }
}
